package com.dby.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.dby.entry.BlogUser;
import com.dby.mapper.BlogUserMapper;
import com.dby.service.BlogUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BlogUserServiceImpl implements BlogUserService{
    @Autowired
    BlogUserMapper blogUserMapper;
    @Override
    public BlogUser getBlogUserByUserCode(String userCode) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("user_code",userCode);

        List<BlogUser> blogUserList = blogUserMapper.selectList(queryWrapper);
        if(blogUserList.size()>0){
            return blogUserList.get(0);
        }
        return null;
    }

    @Override
    public void updBlogUser(BlogUser blogUser) {
        blogUserMapper.updateById(blogUser);
    }

    @Override
    public List<BlogUser> getBlogUserByPage() {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.orderByDesc("create_time");
        return blogUserMapper.selectList(queryWrapper);
    }

    @Override
    public void addBlogUser(BlogUser blogUser) {
        blogUserMapper.insert(blogUser);
    }
    @Override
    public void  delBlogUser(String id){
        blogUserMapper.deleteById(Integer.valueOf(id));
    }

    @Override
    public BlogUser getBlogUserById(String id) {
        return blogUserMapper.selectById(Integer.valueOf(id));
    }

}
